package com.nebula.api.modules.goods.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nebula.commons.modules.log.LogModules;

import com.nebula.api.modules.goods.entity.GoodsInfo;
import com.nebula.api.modules.goods.service.IGoodsInfoService;

import link.ahsj.core.annotations.AddGroup;
import link.ahsj.core.annotations.SameUrlData;
import link.ahsj.core.annotations.SysLog;
import link.ahsj.core.annotations.UpdateGroup;
import link.ahsj.core.entitys.ApiModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author Eastern unbeaten
 * @since 2022-09-11
 */
@RestController
@RequestMapping("goods")
public class GoodsInfoController {

    @Autowired
    private IGoodsInfoService entityService;

    private static final String LogModule = "表说明";

    @RequestMapping("list")
    public ResponseEntity<ApiModel> page(Page page) {
        return ResponseEntity.ok(ApiModel.data(entityService.page(page)));
    }

    @SameUrlData
    @PostMapping("save")
    @SysLog(value = LogModules.SAVE, module = LogModule)
    public ResponseEntity<ApiModel> save(@Validated({AddGroup.class}) @RequestBody GoodsInfo entity) {
        entityService.save(entity);
        return ResponseEntity.ok(ApiModel.ok());
    }

    @SameUrlData
    @SysLog(value = LogModules.UPDATE, module = LogModule)
    @PutMapping("update")
    public ResponseEntity<ApiModel> update(@Validated({UpdateGroup.class}) @RequestBody GoodsInfo entity) {
        entityService.updateById(entity);
        return ResponseEntity.ok(ApiModel.ok());
    }

    @SysLog(value = LogModules.DELETE, module = LogModule)
    @DeleteMapping("delete/{id}")
    public ResponseEntity<ApiModel> delete(@PathVariable("id") String id) {
        entityService.removeById(id);
        return ResponseEntity.ok(ApiModel.ok());
    }

}
